package gui.jquery.chrono.views;
import gui.jquery.chrono.managers.DisplayManager;

import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.UIManager;
import java.awt.Color;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;

import javax.swing.ButtonGroup;
import javax.swing.JRadioButton;
import javax.swing.JComboBox;
import javax.swing.JCheckBox;

/**
 * 
 * @author MAMATU
 *
 */

@SuppressWarnings("serial")
public class ChronoDisplayPanel extends JPanel implements MouseListener, ItemListener {
	
	private DisplayManager manager;
	private ButtonGroup group;
	private JComboBox<Object> deroulant_color;
	private JRadioButton rb_square;
	private JRadioButton rb_none;
	private JRadioButton rb_circle;
	private JCheckBox cB_values;
	

	
	/**
	 * GET&SET
	 */
	public DisplayManager getManager() {return manager;}
	
	public String getColor(){
		return deroulant_color.getSelectedItem().toString();
	}
	
	public FormType getFormType(){
		if (rb_circle.isSelected()) return FormType.CIRLCE;
		if (rb_square.isSelected()) return FormType.RECTANGLE;
		if (rb_none.isSelected()) return FormType.NONE;
		return null;
	}
	
	public boolean valueAreVisible(){
		return cB_values.isSelected();
	}
	
	

	/**
	 * Create the panel.
	 */
	public ChronoDisplayPanel() {
		setBorder(new TitledBorder(null, "Display", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		setLayout(null);
		
		group = new ButtonGroup();
		
		manager = new DisplayManager(this);
		
		JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Slyle", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		panel.setBounds(10, 76, 425, 58);
		
		add(panel);
		
		rb_circle = new JRadioButton("Circle");
		rb_circle.setBounds(50, 22, 64, 23);
		rb_circle.addMouseListener(this);
		rb_circle.setSelected(true);
		group.add(rb_circle);
		panel.add(rb_circle);
		
		rb_square = new JRadioButton("Square");
		rb_square.setBounds(163, 22, 64, 23);
		rb_square.addMouseListener(this);
		panel.add(rb_square);
		group.add(rb_square);
		
		rb_none = new JRadioButton("None");
		rb_none.setBounds(277, 22, 64, 23);
		rb_none.addMouseListener(this);
		panel.add(rb_none);
		group.add(rb_none);
		
		JPanel panel_1 = new JPanel();
		panel_1.setLayout(null);
		panel_1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Color", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		panel_1.setBounds(10, 25, 206, 49);
		add(panel_1);
		
		deroulant_color = new JComboBox<Object>();
		deroulant_color.addItemListener(this);
		//deroulant_color.addMouseListener(this);
		
		deroulant_color.setBounds(47, 18, 111, 20);
		panel_1.add(deroulant_color);
		
		JPanel panel_2 = new JPanel();
		panel_2.setLayout(null);
		panel_2.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Values", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		panel_2.setBounds(225, 25, 208, 49);
		add(panel_2);
		
		cB_values = new JCheckBox("Show");
		cB_values.setBounds(76, 18, 60, 23);
		cB_values.addMouseListener(this);
		panel_2.add(cB_values);
		
		ArrayList<String> params = new ArrayList<String>();
		params.add("Red");
		params.add("Blue");
		params.add("Green");
		setComboBox(params);

	}
	
	
	/**
	 * Permet de remplire la combobox des dimention disponiblie
	 * 
	 * @param params liste de string 
	 */
	public void setComboBox(ArrayList<String> params){
		
		deroulant_color.removeAllItems();
		for (String s : params){
			deroulant_color.addItem(s);
			
		}
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
		manager.getGlobalManager().updateRequest();
		
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		
		

	}

	@Override
	public void mouseReleased(MouseEvent arg0) {

		
	}

	@Override
	public void itemStateChanged(ItemEvent e) {
		if (manager != null && manager.getGlobalManager() != null) {
			manager.getGlobalManager().updateRequest();
		}
		
	}

}
